package com.example.springboottest.example.netty.kyro;

import com.example.springboottest.student.model.Student;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class KyroServerHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg)
            throws Exception {

        System.out.println("server receive msg:" + msg);
        Student student = (Student) msg;
        student.setName("tom");
        student.setAddress("上海市");
//        Student student = new Student("001", "tom", 21, "武汉市");

        System.out.println("server write msg:" + student.toString());
        ctx.writeAndFlush(student);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
            throws Exception {
        cause.printStackTrace();
        ctx.close();
    }

}